$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	 var formData = new FormData($('#signupForm')[0]);  

		
		$.ajax({
			cache : false,
			type : "POST",
			url : "/system/news/save",
			data : formData,// 你的formid  
	        processData: false,  
	        contentType: false,
			error : function(request) {
				parent.layer.alert("Connection error");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("操作成功");
					parent.reLoad();
					var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);

				} else {
					parent.layer.alert(data.msg)
				}

			}
		});
}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			title : {
				required : true
			},
			source : {
				required : true
			},
			content : {
				required : true
			},
			file : {
				required : true
			}
		
		},
		messages : {
			title : {
				required : icon + "请输入新闻标题"
			},
			source: {
				required : icon + "请输入新闻来源"
			},
			content : {
				required : icon + "请输入新闻内容"
			},
			file : {
				required : icon + "上传图片不能为空"
			}
		}
	})
}